/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DBLayer;

import DBLayer.Interfaces.IContainer;
import ModelLayer.Customer;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Moulde
 */
public class DBCustomer extends DatabaseAccess implements IContainer<Customer>
{
    public DBCustomer()
    {
        super();

    }

    public Customer getObject(int customerID)
    {
        String query = "Select CustomerID as ID, RoleID, DiscountTypeID, TotalSpent From Customer WHERE CustomerID = " + customerID;
        ResultSet result = ExecuteQuery(query);

        GenericModelBinder<Customer> binder = new GenericModelBinder<Customer>(Customer.class);
        try
        {
            return binder.BindModel(result);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            Logger.getLogger(DBCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public Customer getCustomerByActorID(int actorID)
    {
        String query = "Select CustomerID as ID, Customer.RoleID, DiscountTypeID, TotalSpent, ActorID From Customer, Role Where Role.RoleID = Customer.RoleID and Role.ActorID = " + actorID;
        ResultSet result = ExecuteQuery(query);

        GenericModelBinder<Customer> binder = new GenericModelBinder<Customer>(Customer.class);

        try
        {
            return binder.BindModel(result);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            Logger.getLogger(DBCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public ArrayList<Customer> getObjects()
    {
        String query = "Select CustomerID as ID, Customer.RoleID, DiscountTypeID, TotalSpent From Customer";
        ResultSet result = ExecuteQuery(query);

        GenericModelBinder<Customer> binder = new GenericModelBinder<Customer>(Customer.class);

        try
        {
            return binder.BindModels(result);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            Logger.getLogger(DBCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return null;
    }

    public boolean SaveObject(Customer object)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean DeleteObject(Customer object)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean UpdateObject(Customer object)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
